package Top200;

import java.util.HashMap;

/**
 * @author zhangmin
 * @create 2022-02-17 10:37
 * 滑动窗口
 */
public class lengthOfLongestSubstring03 {

    public int lengthOfLongestSubstring(String s) {
        HashMap<Character,Integer> windows=new HashMap<>();
        int left=0,right=0;
        int res=0;
        while (right<s.length()){
            char c = s.charAt(right);
            right++;
            windows.put(c,windows.getOrDefault(c,0)+1);
            while (windows.get(c)>1){
                char d = s.charAt(left);
                windows.put(d,windows.getOrDefault(d,0)-1);
                left++;
            }
            res=Math.max(res,right-left);
        }
        return res;
    }
}
